<?php 

  $cmd='./../perllib/GetBandwidthData.pl '.EscapeShellArg($_SESSION["clientbandwidth"]);

  $returnval = exec($cmd, $output, $result); 

  if(preg_match("/Error/", $output[3])) { echo("<br/><br/>".$output[3])."<br/><br/>"; }

  else{

  echo ('<br/><br/><br/><br/><br/><span class="colum0">Month</span><span class="colum1">Year</span> <span class="colum2">Bandwidth</span><br/><br/>');

  rsort($output);

  foreach($output as $x) {
    $date = "";
    $time = "";

    sscanf($x,"Generated %s %s %s",$date, $time, $timeZone);

    if($date) { print '<span class="timestamp">Last updated on the '.$date." at ".$time." $timeZone</span>"; } 
    elseif(!($x == "Content-type:text/html") && !($x == "True")) { //removes unwanted lines

    $array = explode("|", $x);

    $bandwidth = $array[3];
    $bandwidth = strrev($bandwidth);     #Reverse String
    $bandwidth = preg_replace("/([0-9]{3})/", "$1,", $bandwidth);
    $bandwidth = strrev($bandwidth);     #Re-reverse String
    $bandwidth = preg_replace("/^,([0-9,]+)/", " $1", $bandwidth);

    echo('<span class="colum0">'.$array[1].'</span><span class="colum1">'.$array[2].'</span> <span class="colum2">'.$bandwidth.'kB</span><br/>'); 
    } 
  }

  echo('<br/><br/><br/><br/></div>');

  }

?>
